<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>高校教材管理系统-登录</title>
	<%@ include file="./model/link.jsp" %>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-flow: column;
        }
    </style>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/smooth-sliding-menu.js"></script>
</head>
<body>

	<section id="main">
        <div class="title">
            高校教材管理系统
        </div>
        <% 
        	String IS_REG = "false";
        	try{
    	        if(request.getAttribute("IS-REG").equals("true")){
    	        	IS_REG = (String) request.getAttribute("IS-REG"); 
    	        }
        	}catch(NullPointerException e){}
        %>
        
        <% 
        	String IS_ADMIN_TIME_END = "false";
        	try{
    	        if(request.getAttribute("IS-ADMIN_TIME_END").equals("true")){
    	        	IS_ADMIN_TIME_END = (String) request.getAttribute("IS-ADMIN_TIME_END"); 
    	        }
        	}catch(NullPointerException e){}
        %>
        
        <div id="tip"></div>
        
        <% if(IS_REG.equals("true")){ %>
        	<script>
        	jQuery('#tip').stop().fadeIn().text("注册成功！！！")
	            setTimeout(function () {
	            	jQuery('#tip').stop().fadeOut()
	            }, 1500)
        	</script>
        <% } else if(IS_ADMIN_TIME_END.equals("true")){ %>
        	<script>
        	jQuery('#tip').stop().fadeIn().text("登录过期，请重新登录！！！")
	            setTimeout(function () {
	            	jQuery('#tip').stop().fadeOut()
	            }, 1500)
        	</script>
        <% } %>
        
        <div class="widget">
            <div class="login-content">
                <div class="widget-content" style="padding-bottom:0;">
                    <form method="POST" action="#" class="no-margin"
                        onsubmit="return checkLogin(this);">
                        <h3 class="form-title">管理员登录</h3>

                        <fieldset>
                            <div class="form-group no-margin">
                                <label for="adminId">账号</label>
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">
                                        <i class="icon-user"></i>
                                    </span>
                                    <input type="text" placeholder="请输入账号" name="userAcount" class="form-control input-lg"
                                        id="adminId" />
                                </div>

                            </div>

                            <div class="form-group">
                                <label for="password">密码</label>
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">
                                        <i class="icon-lock"></i>
                                    </span>
                                    <input type="password" placeholder="请输入你的密码" class="form-control input-lg"
                                        id="password" name="pwd" />
                                </div>
                            </div>
                        </fieldset>
                        <div class="login-footer">
                            <input type="submit" value="登录">
                            <a class="login-to-reg" href="${pageContext.request.contextPath}/reg">先去注册</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>

    <script>
        function checkLogin(form) {
            if (form.userAcount.value == '' || form.pwd.value == '') {
            	jQuery('#tip').stop().fadeIn().text('账号或密码不可为空！！！')
                setTimeout(function () {
                	jQuery('#tip').stop().fadeOut()
                }, 1500)
                return false
            } else {
            	 jQuery.ajax({
                    method: 'post',
                    url: '/TeachingTest/LoginServlet',
                 	data: jQuery(form).serialize(),
                 	dataType : "text",
                 	error : function (error){
                 		console.log(error)
                 	},
                 	success : function (res){
                 		res = JSON.parse(res)
                 		if (res.status != '200') {
                        	 jQuery('#tip').stop().fadeIn().text(res.infoMsg)
                             setTimeout(function () {
                                jQuery('#tip').stop().fadeOut()
                             }, 1500)
                        }else {
                         	window.location.href = "/TeachingTest/main?page=index&target=0"
                        }
                 	}
                 })
                return false
            }
        }
    </script>
</body>
</html>